﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DistributedSystems.Object;

namespace DistributedSystems
{
    public class DateTimeUtils
    {
        // 1: morning
        // 2: lun
        // 3: all day
        public static List<TimeHell> ConvertHourToListDay(DateTime datetimebegin, double minutes)
        {
            List<TimeHell> result = new List<TimeHell>();

            DateTime Twomorrow = datetimebegin.AddDays(1);
            DateTime good = new DateTime(Twomorrow.Year, Twomorrow.Month, Twomorrow.Day);
            TimeSpan time = good - datetimebegin;
            double a = time.TotalMinutes;
            if (a > minutes)
            {
                TimeHell thell = new TimeHell(datetimebegin, minutes);
                result.Add(thell);
            }
            else
            {
                double minu = minutes - a;
                TimeHell temp = new TimeHell(datetimebegin, a);
                result.Add(temp);

                int day = (int)minu / (60 * 24);
                int remMinute = (int)minu % (60 * 24);
                if (day > 0)
                {
                    int i = 0;
                    for (; i < day; i++)
                    {
                        temp = new TimeHell(good.AddDays(i), 60 * 24);
                        result.Add(temp);
                    }
                    if (remMinute > 0)
                    {
                        temp = new TimeHell(good.AddDays(i), remMinute);
                        result.Add(temp);
                    }
                }
                else
                {
                    if (remMinute > 0)
                    {
                        temp = new TimeHell(good, remMinute);
                        result.Add(temp);
                    }
                }
            }
            return result;
        }
        public static int CheckStateMoney(TimeHell timehell, int HourRate) // hourRate : 5(ACT)
        {
            int result = 0;
            int hourBegin = timehell.CurentDay.Hour;
            int hour = (int)timehell.Minutes/ (60 * 24);
            if (hour >= 12)
                return 3;
            if ((hourBegin >= HourRate) && (hourBegin <= (HourRate + 12)))
            {
                if (hourBegin + hour > HourRate + 12)
                    return 3;
                return 2;
            }
            if (hourBegin < HourRate)//  2h am  < 5
            {
                if (hourBegin + hour > hourBegin)
                    return 3;
                else
                    return 1;
            }
            if (hourBegin > HourRate + 12)
                return 1;
            return result;
        }
    }
}